/*
check browser settings for MathML

2005/03/27
 extracted from http://www.chapman.edu/~jipsen/mathml/ASCIIMathML.js
 and slightly modified
*/

// check if browser can display MathML
var checkForMathML = true;
// put note at top of page if no MathML capability
var notifyIfNoMathML = true;
var isIE = document.createElementNS==null;

if (document.getElementById==null) 
  alert("This webpage requires a recent browser such as\
\nMozilla/Netscape 7+ or Internet Explorer 6+MathPlayer")

// all further global variables start with "AM"

function MLcreateElementXHTML(t) {
  if (isIE) return document.createElement(t);
  else return document.createElementNS("http://www.w3.org/1999/xhtml",t);
}

function isMathMLavailable() {
  var nd = MLcreateElementXHTML("center");
  nd.appendChild(document.createTextNode("To view the "));
  var an = MLcreateElementXHTML("a");
  an.appendChild(document.createTextNode("MathML"));
  an.setAttribute("href","http://www.w3.org/math");
  nd.appendChild(an);
  nd.appendChild(document.createTextNode(" notation use Internet Explorer 6+"));  
  an = MLcreateElementXHTML("a");
  an.appendChild(document.createTextNode("MathPlayer"));
  an.setAttribute("href","http://www.dessci.com/en/products/mathplayer/download.htm");
  nd.appendChild(an);
  nd.appendChild(document.createTextNode(" or Netscape/Mozilla/Firefox"));
  if (navigator.appName.slice(0,8)=="Netscape") 
    if (navigator.appVersion.slice(0,1)>="5") return null;
    else return nd;
  else if (navigator.appName.slice(0,9)=="Microsoft")
    try {
        var ActiveX = new ActiveXObject("MathPlayer.Factory.1");
        return null;
    } catch (e) {
        return nd;
    }
  else return nd;
}

var MLmathml = "http://www.w3.org/1998/Math/MathML";

function MLcreateElementMathML(t) {
  if (isIE) return document.createElement("mml:"+t);
  else return document.createElementNS(MLmathml,t);
}

function MLcreateMmlNode(name,frag) {
  var node = MLcreateElementMathML(name);
  node.appendChild(frag);
  return node;
}

function checkBrowser() {
  var nd = isMathMLavailable();
  noMathML = nd != null;
  if (noMathML && notifyIfNoMathML) {
    mbody = document.getElementsByTagName("body")[0];
    mbody.insertBefore(nd,mbody.childNodes[0]);
  }
}

checkBrowser();
